{include file="public/header"}

<body>
    <div class="layui-fluid">
        <div class="layui-row">
            <form action="" method="post" class="layui-form layui-form-pane">
                <div class="layui-card layui-form" lay-filter="component-form-element">
                    <div class="layui-card-header">类型</div>
                    <div class="layui-card-body layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <input type="radio" name="type" lay-filter="type" value="1" {if !empty($row.type) &&
                                $row.type==1}checked{/if} title="平台通用">
                            <input type="radio" name="type" lay-filter="type" value="2" {if !empty($row.type) &&
                                $row.type==2}checked{/if} title="绑定商家">
                        </div>
                    </div>
                </div>
                <div class="layui-card layui-form" lay-filter="component-form-element" id="provinceshow"
                    style="display: none;">
                    <div class="layui-card-header">选择商家</div>
                    <div class="layui-card-body layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <select name="business" lay-search=''>
                                <option value="">请选择商家</option>
                                {foreach $business as $v}
                                <option value="{$v.id}">{$v.title}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-card layui-form" lay-filter="component-form-element">
                    <div class="layui-card-header">达到消费金额，单位:元</div>
                    <div class="layui-card-body layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <input type="number" id="getmoney" name="getmoney" required="" lay-verify="required"
                                autocomplete="off" class="layui-input" value="{$row.getmoney|default='0'}"
                                placeholder="">
                        </div>
                        <div class="layui-form-mid" style="color: #FF5722;">
                            需要达到购物的消费金额，填0表示无条件使用
                        </div>
                    </div>
                </div>
                <div class="layui-card layui-form" lay-filter="component-form-element">
                    <div class="layui-card-header">券面值，单位:元</div>
                    <div class="layui-card-body layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <input type="number" id="money" name="money" required="" lay-verify="required"
                                autocomplete="off" class="layui-input" value="{$row.money|default='1'}" placeholder="">
                        </div>
                        <div class="layui-form-mid" style="color: #FF5722;">
                            达到消费金额后的减免金额
                        </div>
                    </div>
                </div>
                <div class="layui-card layui-form" lay-filter="component-form-element">
                    <div class="layui-card-header">有效期,单位:天</div>
                    <div class="layui-card-body layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <input type="number" id="days" name="days" required="" lay-verify="required"
                                autocomplete="off" class="layui-input" value="{$row.days|default='0'}" placeholder="">
                        </div>
                        <div class="layui-form-mid" style="color: #FF5722;">
                            赠送时间后的有效天数
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <input type="hidden" value="{$id|default='0'}" name="user_id" />
                    <button class="layui-btn" lay-submit="" lay-filter="add">提交</button>
                </div>
            </form>
        </div>
    </div>
    {include file="public/footer"}
    <script>
        layui.use(['form', 'layer', 'upload'], function () {
            $ = layui.jquery;
            var form = layui.form
                , upload = layui.upload
                , element = layui.element
                , layer = layui.layer;
            form.on('radio(type)', function (data) {
                var type = data.value;
                if (type == 1) {
                    $('#provinceshow').hide();
                }
                if (type == 2) {
                    $('#provinceshow').show();
                }
            });
            form.on('submit(add)', function (data) {
                $.ajax({
                    type: 'post',
                    data: data.field,
                    success: function (res) {
                        if (res.status == 0) {
                            layer.msg(res.msg, { icon: 6, time: 1000 }, function () {
                                // 获得frame索引
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.location.reload();
                                parent.layer.close(index);
                            });
                        } else {
                            layer.msg(res.msg, { icon: 2, time: 1000 });
                        }
                    }
                });
                return false;
            });
        });
    </script>